/**
 * AvatarImageController
 *
 * @description :: Server-side logic for managing Avatarimages
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

module.exports = {
	createNew: function(req, res, next){
		console.log('sup homie')
		var avatarImageParams = req.params.all()
		var avatarImage = req.file('file')
		
		avatarImage.upload({ dirname: '../../assets/images'}, function onUploadComplete (err, files) {
			//upload files to .tmp/uploads
			if (err) {
				return res.serverError(err)
			}

			console.log(files);
			res.json({status:200, file:files});

			AvatarImage.create({url: files[0].fd, fileType: files[0].type, user: avatarImageParams.user})
			.exec(function (err, created){
				if (err){
					console.log(err)
				}
			})

		})

	}
	
};

